package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;

public class RabidSplash extends JFrame {
  private static final long serialVersionUID = -8024072019329733152L;
  
  public RabidSplash() {
    create();
  }
  
  private void create() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    
    setLocationRelativeTo(this);
    setUndecorated(true);
    setResizable(false);
    
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());      
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    
    JPanel pnlMain = new JPanel();
    pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.PAGE_AXIS));
    pnlMain.setBackground(Color.BLACK);
    
    JLabel lblImage = new JLabel(getSplashImage());
    lblImage.setAlignmentX(Component.CENTER_ALIGNMENT);
    lblImage.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
        
    JProgressBar bar = new JProgressBar();
    bar.setIndeterminate(true);
    pnlMain.add(lblImage);
    pnlMain.add(bar);
    getContentPane().add(pnlMain, BorderLayout.CENTER);
  }
  
  private static ImageIcon getSplashImage() {
    java.net.URL imgURL = RabidSplash.class.getResource("splash-image.gif");
    if (imgURL != null) {
      return new ImageIcon(imgURL);
    }
    else {
      System.err.println("Couldn't find splash image");
      return null;
    }
  }
  
  public void showSplash() {    
    pack();
    setVisible(true);
  }
  
  public void hideSplash() {
    setVisible(false);
  }
  
  public static void main(String[] args) {
    new RabidSplash().showSplash();
  }

}
